import React from 'react';
import { observer, inject } from 'mobx-react';
import { WeaErrorPage,WeaTools, WeaLocaleProvider, WeaTab } from 'ecCom';
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import * as _ from '../../util/common';
import '../../style/formResource.less';
import CommunicationRichText from './CommunicationRichText';
import ContentList from './ContentList';
import MyContentList from './MyContentList';
import Condition from './Condition';
import Resource from './Resource';
import ContentItem from './ContentItem';
import '../../style/communication.less';
import '../../style/communicationIcon.css';
import { message, Pagination, Button} from 'antd';
import { toJS } from 'mobx';
import QuoteItem from './QuoteItem'
const getLabel = WeaLocaleProvider.getLabel;

@observer
class index extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            showSearchAd : false,
        }
    }

    componentDidMount() {
        const { WfFormCommunicationStore, commonParam, WfFormCommunicationStore:{reflashContentList} } = this.props;
        let baseParam = {};
        const range = ["requestid", "workflowid", "f_weaver_belongto_userid", "f_weaver_belongto_usertype", "authStr", "authSignatureStr", 'isurger'];
        range.map(key =>{
            baseParam[key] = commonParam[key];
        });
        WfFormCommunicationStore.init(baseParam);
        let wrapDiv = document.getElementsByClassName('wea-new-top-req-content')[0];
        wrapDiv.style.overflowY = 'auto';
        window.reflashCommunicateContentList = reflashContentList;
    }

   
    render(){
        const { WfFormCommunicationStore, commonParam, clearReplyInfo } = this.props;
        const { contentList = [], status = {}, hasDot, adSearchForm, adSearchCondition,reflashContentList,hasdate,setState, hasSubmitRight } = WfFormCommunicationStore;
        let {srchcontent} = adSearchForm.getFormParams();
        return (
            <div className="wea-workflow-communication">
             {
               hasSubmitRight && 
               <CommunicationRichText ecId={`${this && this.props && this.props.ecId || ''}_CommunicationRichText@q6pu27`} requestid={commonParam.requestid} appStatus={WfFormCommunicationStore.appStatus} submit={WfFormCommunicationStore.saveContent} noNeedCancelBtn={true}/>
             }
               
                <div className="wea-workflow-communication-content">
                {hasdate ?
                   <div>
                    <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@qraxp5`}
                      datas={[
                      {title: getLabel(512070, '全部'), key: 'list'},
                      {
                          titleText: getLabel(32572, '与我相关'),
                          title: (<div className="cowork-my" onClick={this.dotClick}>{getLabel(32572, '与我相关')}
                          <span className={hasDot ? "cowork-my-dot" : "cowork-my-dotHide"}></span></div>), key: 'relatedme'
                      },
                      {title:  getLabel(512294, "交流资源"), key: 'resource'},
                      ]}
                      size="small"
                      keyParam='key'
                      leftStyle={{width: '44%'}}
                      rightStyle={{width: '56%'}}
                      selectedKey={status.tabKey}
                      onChange={this.changeTabKey}
                      searchType={status.tabKey == 'list' ? "base,advanced" : ""}
                      onSearch={() => {
                        setState({currentPage : 1});
                        reflashContentList();
                      }}  
                      searchsBaseValue={srchcontent}
                      // // onSearchChange={this.onSearchChange}
                      onSearchChange={v => adSearchForm.updateFields({srchcontent: v})}
                      showSearchAd={this.state.showSearchAd}
                      setShowSearchAd={(bool) => {this.setState({showSearchAd : bool})}}
                      hasMask={false}
                      searchsAd={<Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@5p3ya2`}
                          queryStore={{form:adSearchForm,condition:adSearchCondition}}
                          type='AdSearch'
                      />}
                      advanceHeight={120}
                      buttonsAd={[
                      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@okxqsg@search`} type="primary" onClick={() => {this.setState({showSearchAd : false, currentPage : 1});reflashContentList();}}>{getLabel(197, '搜索')}</Button>),
                      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@tp49kk@reset`} type="ghost" onClick={() => {adSearchForm.resetForm();}}>{getLabel(2022, '重置')}</Button>),
                      (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@legjhr@cancel`} type="ghost" onClick={() => {this.setState({showSearchAd : false})}}>{getLabel(201, '取消')}</Button>)
                      ]}
                    />
                   
                    {status.tabKey == "list" && <ContentList ecId={`${this && this.props && this.props.ecId || ''}_ContentList@10isqj`} WfFormCommunicationStore={WfFormCommunicationStore} commonParam={commonParam}/>}
                    {status.tabKey == "relatedme" && <MyContentList ecId={`${this && this.props && this.props.ecId || ''}_MyContentList@zfacep`} WfFormCommunicationStore={WfFormCommunicationStore} commonParam={commonParam}/>}
                    {status.tabKey == "resource" && <Resource ecId={`${this && this.props && this.props.ecId || ''}_Resource@3f3vbo`} WfFormCommunicationStore={WfFormCommunicationStore} commonParam={commonParam}/>}
                    </div> : 
                    <div style={{borderBottom : 0, marginTop : 20}} className="ant-table-placeholder">
                        <i className="anticon anticon-frown"></i>
                        <sapn>{getLabel(389967, '暂无相关交流')}</sapn>
                    </div>
                }
                </div>
            </div>
        )
    }

    changeTabKey = (tabKey) => {
        this.props.WfFormCommunicationStore.setState({tabKey: tabKey, currentPage : 1}, this.props.WfFormCommunicationStore.reflashContentList);
    }

    //红点显示隐藏
    dotClick = () => {
        this.props.WfFormCommunicationStore.hideDot();
    }
}

export default WeaTools.tryCatch(React, 
    props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@fs4c6b`} msg={ props.error ? props.error : getLabel(383324,'对不起，该页面异常，请联系管理员')} />,
    {error: ""}
)(index);